//
//  TTZuanshiTextScopeView.m
//  TaoTuo
//
//  Created by LG on 2020/10/26.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTZuanshiTextScopeView.h"

@interface TTZuanshiTextScopeView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) UIView *lineView;     // 线
/// 开始编辑, 是不是左侧的输入框
@property (nonatomic, copy) void(^startEditBlock)(BOOL isLeftTF);

@end

@implementation TTZuanshiTextScopeView

- (instancetype)initWithFrame:(CGRect)frame title:(nonnull NSString *)title startEdit:(nonnull void (^)(BOOL))startEdit
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.title = title;
        self.startEditBlock = startEdit;
        [self setupSubviews];
        
    }
    return self;
}

/// 开始编辑
- (void)startEditAction:(UITextField *)tf
{
    BOOL left = tf == self.minTF;
    if (self.startEditBlock) {
        self.startEditBlock(left);
    }
}

- (void)resetView
{
    self.minTF.text = @"";
    self.maxTF.text = @"";
}

- (void)setMinStr:(NSString *)minStr maxStr:(NSString *)maxStr
{
    self.minTF.text = minStr;
    self.maxTF.text = maxStr;
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:self.title color:UIColorHex(#333333) font:[UIFont boldSystemFontOfSize:15]];
    _titleLabel.frame = CGRectMake(10, 0, self.width, 30);
    [self addSubview:_titleLabel];
    
    CGFloat w = (self.width - 45) * 0.5;
    _minTF = [[UITextField alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom + 5, w, 30)];
    _minTF.backgroundColor = UIColorHex(#F5F5F5);
    _minTF.keyboardType = UIKeyboardTypeDecimalPad;
    _minTF.textAlignment = NSTextAlignmentCenter;
    _minTF.textColor = UIColorHex(333333);
    _minTF.layer.cornerRadius = 15;
    _minTF.font = [UIFont systemFontOfSize:15];
    [_minTF addTarget:self action:@selector(startEditAction:) forControlEvents:UIControlEventEditingDidBegin];
    [self addSubview:_minTF];
    
    _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 7, 2)];
    _lineView.center = CGPointMake(self.centerX, _minTF.centerY);
    _lineView.backgroundColor = UIColorHex(666666);
    [self addSubview:_lineView];
    
    _maxTF = [[UITextField alloc] initWithFrame:CGRectMake(_lineView.right + 9, _minTF.top, w, 30)];
    _maxTF.backgroundColor = UIColorHex(#F5F5F5);
    _maxTF.keyboardType = UIKeyboardTypeDecimalPad;
    _maxTF.textAlignment = NSTextAlignmentCenter;
    _maxTF.textColor = UIColorHex(333333);
    _maxTF.layer.cornerRadius = 15;
    _maxTF.font = [UIFont systemFontOfSize:15];
    [_maxTF addTarget:self action:@selector(startEditAction:) forControlEvents:UIControlEventEditingDidBegin];
    [self addSubview:_maxTF];
    
    self.height = _titleLabel.height + _minTF.height + 10;
    
}


@end
